package io

import (
	"fmt"
	"strings"
)

func GenerateConfdWatchValue(hosts []string) (apiUrls map[string]string) {
	apiUrls = make(map[string]string, 2)
	var httpsUrl string
	var httpUrl string
	for _, hostIP := range hosts {
		httpsUrl += hostIP + ":6444;"
		httpUrl += hostIP + ":8080;"
	}

	httpsUrlLast := len(httpsUrl) - 1
	httpUrlLast := len(httpUrl) - 1
	apiUrls["https"] = httpsUrl[0:httpsUrlLast]
	apiUrls["http"] = httpUrl[0:httpUrlLast]

	return apiUrls
}

func ConfdTest() {
	a := []string{"1.1.1.1", "2.2.2.2", "3.3.3.3"}
	var b string
	fmt.Println(len(a))
	for _, elem := range a[1:] {
		b += elem + " "
	}
	fmt.Println(len(b), b)
	fmt.Println(strings.Trim(b, " "))
	fmt.Println(len(b))

	c := len(a) - 1
	fmt.Println(a[0:c])

	etcdEndPoints := "https://20.26.38.124:2379;https://20.26.38.127:2379;https:abc//20.26.38.126:2379"

	etcdServers := strings.Replace(etcdEndPoints, ";", ",", -1)
	fmt.Println(etcdServers)
	value := GenerateConfdWatchValue([]string{"1.2.3.4"})
	fmt.Println(value)

	index := strings.Index(etcdEndPoints, "abc")
	fmt.Println(index, etcdEndPoints[index:])
}
